#include <stdio.h>
#include <stdlib.h>

int main(){
    int *arr;
    int n,i;
    //Using malloc
    n=5;
    arr=(int *)malloc(n*sizeof(int));
    if(arr==NULL){
        printf("Memory allocation failed\n");
        return 1;
    }
    for(i=0;i<n;i++){
        arr[i]=i+1;
    }

    printf("Array Elements using malloc: ");
    for(i=0;i<n;i++){
        printf("%d ",arr[i]);
    }

    printf("\n");

    // Using calloc
    n=5;
    arr=(int *)calloc(n,sizeof(int));
    if(arr==NULL){
        printf("Memory allocation failed\n");
        return 1;
    }
    for(i=0;i<n;i++){
        arr[i]=i+1;
    }
    printf("Array Elements using calloc: ");
    for(i=0;i<n;i++){
        printf("%d ",arr[i]);
    }
    printf("\n");
    //Using remalloc
    n=10;
    arr=(int *)realloc(arr,n*sizeof(int));
    if(arr==NULL){
        printf("Memory allocation failed\n");
        return 1;
    }
    for(i=5;i<n;i++){
        arr[i]=i+1;
    }
    printf("Array Elements using realloc: ");
    for(i=0;i<n;i++){
        printf("%d ",arr[i]);
    }
    printf("\n");
    free(arr);
    return 0;
}